package com.oa.business.org.dto;

import com.alibaba.fastjson.JSON;
import com.oa.common.DomainDto;
import com.oa.framework.org.department.domain.Department;
import com.oa.framework.org.domain.Duty;
import lombok.Getter;
import lombok.Setter;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/***
 * @author cuichao
 */
@Getter
@Setter
public class DepartmentDto implements DomainDto<Department> {

    private Long departmentId;

    private String departmentCode;

    private String departmentName;

    private Long parentId;

    private Long masterDutyId;

    private List<Long> dutyIds;


    @Override
    public Department transform() {
        Department dept = new Department();
        dept.setDepartmentId(departmentId);
        dept.setDepartmentCode(departmentCode);
        dept.setDepartmentName(departmentName);
        dept.setParentId(parentId);
        dept.setMasterDutyId(masterDutyId);

        if(dutyIds != null){
            List<Duty> collect = dutyIds.stream().map(v -> {
                Duty duty = new Duty();
                duty.setDutyId(v);
                return duty;
            }).collect(Collectors.toList());
            dept.setDuties(collect);
        }
        return dept;
    }
}
